package com.tul.exercise.base.clazz.base.eg6;

import com.tul.exercise.base.clazz.base.eg6.base.Pet;

import java.util.ArrayList;
import java.util.List;
import static com.tul.exercise.base.utils.Print.print;

/**
 * @ClassName ForNameCreator
 * @Description TODO
 * @Author tul 2018/10/12
 * @Version 1.0
 **/
public class ForNameCreator extends PetCreator{
    private static List<Class<? extends Pet>> types = new ArrayList<>();

    private static String packageStr = "com.tul.exercise.base.clazz.base.eg6.base.";

    private static String [] typesNames = {
            packageStr + "Mutt",
            packageStr + "Pug",
            packageStr + "EgyptianMau",
            packageStr + "Manx",
            packageStr + "Cymric",
            packageStr + "Rat",
            packageStr + "Mouse",
            packageStr + "Hamster"

    };
    @Override
    public List<Class<? extends Pet>> types() {
        return types;
    }

    private static void loader() {
        try {
            for(String name:typesNames) {
                types.add((Class<? extends Pet>)Class.forName(name));
            }
        } catch (ClassNotFoundException e) {
            print("加载类异常，class=" + typesNames);
            throw new RuntimeException(e);
        }
    }

    static {
        loader();
    }


}
